import ElckerServiceApi from "@/plugins/axios/index"
import QS from 'qs';
class ElckerAuthService extends ElckerServiceApi {
    private urlComPath: string = "/elckerApi/authService/";
    userLogin(data: any) {
        return this.LoginPostRequest({
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            },
            url: this.urlComPath + "login",
            method: 'POST',
            params: QS.stringify({
                username: data.username,
                password: data.password,
                grantType: 'password',//grant_type表示授权类型，固定为"password"，必选项
                scope: 'all'//可读写，表示权限范围，可选项
            }),
            auth: {
                username: 'elcauth', // client_id
                password: '123456' // client_secret
            },
            apiSate: false
        });
    }
    userLoginOut(data: any) {
        return this.postRequest({
            url: this.urlComPath + "logout", params: data, method: "POST"
        });
    }
    refreshToken(data: any) {
        return this.postRequest({
            url: this.urlComPath + "refreshToken", params: data, method: "POST"
        });
    }
}

// 单列模式返回对象
let ElckerAuthApi;
export default (() => {
    if (ElckerAuthApi) return ElckerAuthApi;
    ElckerAuthApi = new ElckerAuthService();
    return ElckerAuthApi;
})();